package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type count struct {
	ziMuNum int
}

func main() {
	//file, err := os.Open("1goAdvanced/5file/fileReader/aaa.txt")
	//if err != nil {
	//	fmt.Println("文件读取异常")
	//}
	//defer file.Close()
	//reader := bufio.NewReader(file)
	//for {
	//	readString, err := reader.ReadString('\n')
	//	if err == io.EOF {
	//		break
	//	}
	//	fmt.Println(readString)
	//}
	//fmt.Println("文件读取结束")

	//一次性读取所有文件内容
	//readFile, _ := ioutil.ReadFile("d:/abc.txt")
	//fmt.Println(string(readFile))

	//创建文件并写入内容
	filePath := "d:/abc.txt"
	//file1, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
	//file1, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
	//if err != nil {
	//	fmt.Printf("%v\n", err)
	//}
	//
	//str := "helloWorld\n"
	////bufio.NewWriter(file1)
	//writer := bufio.NewWriter(file1)
	//for i := 0; i < 5; i++ {
	//	writer.WriteString(str)
	//}
	//writer.Flush()
	////ioutil.ReadFile()
	//
	//_, err1 := os.Stat(filePath)
	//if err1 != nil {
	//	fmt.Println("文件有误")
	//}

	file1, _ := os.Open(filePath)
	reader := bufio.NewReader(file1)
	defer file1.Close()
	var cou count
	for {
		readString, err2 := reader.ReadString('\n')
		if err2 == io.EOF {
			break
		}
		runes := []rune(readString)
		for _, v := range runes {
			//fmt.Println(v)
			switch {
			case v >= 'a' && v <= 'z':
				fallthrough
			case v >= 'A' && v <= 'Z':
				cou.ziMuNum++
			}
		}
	}
	fmt.Println(cou.ziMuNum)

}
